﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Elentok.Common.Wpf
{
  /// <summary>
  /// The base interface for view models
  /// </summary>
  public interface IViewModel : INotifyPropertyChanged, INotifyPropertyChanging
  {
  }

  /// <summary>
  /// The base implementation of a view model
  /// </summary>
  public abstract class ViewModelBase : IViewModel
  {
    #region INotifyPropertyChanged Members

    /// <summary>
    /// Occurs when a property value changes.
    /// </summary>
    public event PropertyChangedEventHandler PropertyChanged;

    /// <summary>
    /// Raises the PropertyChanged event
    /// </summary>
    protected virtual void OnPropertyChanged(string propertyName)
    {
      PropertyChangedEventHandler handler = PropertyChanged;
      if (handler != null)
        handler(this, new PropertyChangedEventArgs(propertyName));
    }

    #endregion

    #region INotifyPropertyChanging Members

    /// <summary>
    /// Occurs when a property value is changing.
    /// </summary>
    public event PropertyChangingEventHandler PropertyChanging;

    /// <summary>
    /// Raises the PropertyChanging event
    /// </summary>
    protected virtual void OnPropertyChanging(string propertyName)
    {
      PropertyChangingEventHandler handler = PropertyChanging;
      if (handler != null)
        handler(this, new PropertyChangingEventArgs(propertyName));
    }

    #endregion
  }
}
